Open
Conversation
- Introduced a new structure for status codes in status_codes.h, categorizing errors into Configuration, Connection, Io, Control, and Monitor. - Removed the obsolete status_codes.hpp file, consolidating functionality into status_codes.h. - Updated validation functions in validation.hpp to utilize the new status code structure for improved error handling. - Adjusted documentation in serial_abort_read.h and serial_abort_write.h to reflect changes in status code usage.
- Changed ValueType from std::int32_t to std::int64_t for improved range. - Replaced the make function with a GenCode template structure for generating error codes, enhancing clarity and maintainability. - Updated error codes in Configuration, Connection, Io, Control, and Monitor categories to utilize the new GenCode structure.
- Added an explicit conversion operator to the GenCode template for improved usability. - Updated status code definitions in Configuration, Connection, Io, Control, and Monitor categories to utilize the GenCode structure directly, enhancing clarity and maintainability.
- Moved status code definitions into a new cpp_core::status_codes namespace for better modularity. - Introduced a detail namespace to encapsulate internal structures, enhancing code clarity. - Updated references to ValueType and CategoryBase to reflect the new namespace structure, improving maintainability.
Mqxx
requested changes
Mar 18, 2026
…de definitions and improve code clarity.
- Introduced a new header file status_code.h to define a structured approach for status codes within the cpp_core::status_codes namespace. - Implemented a CategoryBase template for generating error codes, enhancing clarity and maintainability. - Organized status codes into categories: Configuration, Connection, Io, and Control, each with specific error codes for improved usability.
- Changed the CategoryBase template to accept a derived type instead of a category value, enhancing type safety and clarity. - Updated the Configuration, Connection, Io, and Control structs to define their category codes directly, improving maintainability and readability of status code definitions.
- Changed the initialization of kCategoryMultiplier from an assignment to a uniform initialization syntax, enhancing code consistency and clarity.
- Introduced CPP_CORE_STATUS_CATEGORY and CPP_CORE_CODE macros for streamlined status code definitions, improving maintainability and readability. - Added isError and isSuccess functions for better error handling. - Updated the CategoryBase template to support compile-time code generation, enhancing type safety and clarity in status code management.
- Moved isError, isSuccess, and belongsTo functions into the StatusCode struct for better encapsulation and organization. - Updated function signatures to use detail::ValueType for consistency with the new structure. - Removed redundant definitions from the detail namespace, enhancing code clarity and maintainability.
2c35c6e to
2b63c69
Compare
- Refactored the Code template to accept a Category type, improving type safety and clarity. - Introduced new member functions for retrieving the name and category of status codes. - Replaced macro-based status code definitions with structured definitions for Configuration, Connection, and Io categories, enhancing maintainability and readability.
Mqxx
requested changes
Mar 20, 2026
Mqxx
requested changes
Mar 20, 2026
Co-authored-by: Mqx <62719703+Mqxx@users.noreply.github.com>
- Added static assertions to enforce constraints on category and local codes, improving safety against negative values and overflow. - Introduced a new test category, FakeCategory, to validate the computation of status codes, ensuring correct behavior across edge cases and preventing overflow. - Updated test cases to cover various scenarios, enhancing the robustness of the status code generation logic.
Mqxx
requested changes
Mar 21, 2026
Comment on lines
+141
to
+179
| namespace cpp_core::status_codes::detail::tests | ||
| { | ||
|
|
||
| template <int64_t CatCode> struct FakeCategory : CategoryBase<FakeCategory<CatCode>> | ||
| { | ||
| static constexpr ValueType kCategoryCode = CatCode; | ||
|
|
||
| template <ValueType Local> static consteval auto call() -> ValueType | ||
| { | ||
| return CategoryBase<FakeCategory>::template computeValue<Local>(); | ||
| } | ||
| }; | ||
|
|
||
| // Formula: result == -(kCategoryCode * 100 + LocalCode) | ||
| static_assert(FakeCategory<1>::call<0>() == -100); | ||
| static_assert(FakeCategory<1>::call<42>() == -142); | ||
| static_assert(FakeCategory<3>::call<7>() == -307); | ||
|
|
||
| // Edge: kCategoryCode == 0 -> call<0>() produces 0 (not negative) | ||
| static_assert(FakeCategory<0>::call<0>() == 0); | ||
| static_assert(FakeCategory<0>::call<1>() == -1); | ||
|
|
||
| // Edge: LocalCode == 99 (max before overflow guard) | ||
| static_assert(FakeCategory<2>::call<99>() == -299); | ||
|
|
||
| // Consecutive codes differ by exactly -1 | ||
| static_assert(FakeCategory<1>::call<1>() - FakeCategory<1>::call<0>() == -1); | ||
|
|
||
| // Adjacent category ranges don't overlap (last of cat N > first of cat N+1) | ||
| static_assert(FakeCategory<1>::call<99>() > FakeCategory<2>::call<0>()); | ||
|
|
||
| // Overflow: largest safe category still produces correct results | ||
| inline constexpr ValueType kMaxSafeCat = | ||
| (std::numeric_limits<ValueType>::max() - kCategoryMultiplier + 1) / kCategoryMultiplier; | ||
| static_assert(kMaxSafeCat > 1'000'000); | ||
| static_assert(FakeCategory<kMaxSafeCat>::call<0>() == -(kMaxSafeCat * kCategoryMultiplier)); | ||
| static_assert(FakeCategory<kMaxSafeCat>::call<99>() > std::numeric_limits<ValueType>::min()); | ||
|
|
||
| } // namespace cpp_core::status_codes::detail::tests |
Member
There was a problem hiding this comment.
Shouldn't stay in this file. Please refactor to separate test file, like we discussed.
Member
Author
There was a problem hiding this comment.
should stay in this file, like we discussed
Member
There was a problem hiding this comment.
No. Like I said. This is like a unit test, and not to control something platform specific.
Member
There was a problem hiding this comment.
static_asserts should only stay directly in the file if they are used to fail if the condition for the platform is not met and the compiler should fail. You use it for unit testing here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.